﻿
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Share;

public class RequestData
{
    public string Token { get; set; } = string.Empty;
    public ReqData ReqData { get; set; } = new();
}

public class ReqData
{
    /// <summary>
    /// PlainData json  的密文
    /// </summary>
    [JsonPropertyName("data")]
    public string CipherText { get; set; } = string.Empty;

    [JsonPropertyName("timestamp")]
    public string Timestamp => ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString();

    [JsonPropertyName("tslen")]
    public int TsLen => Timestamp.ToString().Length;

    [JsonPropertyName("signdata")]
    public string SignData { get; set; } = string.Empty;

    public override string ToString() => JsonSerializer.Serialize(this);
}

public class PlainData
{
    /// <summary>
    /// 查询id，请求方做到唯一
    /// </summary>
    [JsonPropertyName("id")]
    public Guid? Id { get; set; } = Guid.NewGuid();

    /// <summary>
    /// 身份证号码 
    /// </summary>
    [JsonPropertyName("idcard")]
    [DisplayName("证件号码")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "请输入证件号码")]
    public string IdCard { get; set; } = string.Empty;

    /// <summary>
    /// 姓名(需utf8编码的urlencode) 
    /// </summary>
    [JsonPropertyName("realname")]
    [DisplayName("姓名")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "请输入姓名")]
    public string RealName { get; set; } = string.Empty;

    /// <summary>
    /// 请求方名称 
    /// </summary>
    [JsonPropertyName("vendor")]
    public string Vendor => "ICBC";
}